package alg20241224;

public class Text2 {
    public int maxSubArray(int[] nums) {
        int n = nums.length;
        //1创建表
        int[] dp = new int[n + 1];
        //2初始化

        //3填表
        for (int i = 1; i <= n; i++) {
            dp[i] = Math.max(nums[i - 1], dp[i - 1] + nums[i - 1]);
        }
        //4返回值
        int max = Integer.MIN_VALUE;
        for (int i = 0; i <= n; i++) {
            if(dp[i] > max) {
                max = dp[i];
            }
        }
        return max;

    }
}
